/**  
* @Title: MessageController.java  
* @Description: TODO(用一句话描述该文件做什么)  
* @author 张鑫
* @phone 17561783855  
* @date 2019年7月29日  
*/
package com.fortune.rainshineservice.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.fortune.rainshinecommon.base.MsgModel;
import com.fortune.rainshinecommon.base.ParmsModel;
import com.fortune.rainshinecommon.enums.ResultCode;
import com.fortune.rainshinecommon.model.service.MessageModel;
import com.fortune.rainshineservice.service.MessageService;

/**  
* @ClassName: MessageController  
* @Description: TODO(消息管理)  
* @author 张鑫
* @phone 17561783855
* @date 2019年7月29日  
*    
*/
@RestController
@RequestMapping("/message")
public class MessageController {
	private static final Logger logger = LoggerFactory.getLogger(MessageController.class);
	@Autowired
    private MessageService messageService;
	
	/**
	 * @Title: productList
	 * @Description: 获取消息列表
	 * @author zhangxin
	 * @phone 17561783855
	 * @date 2019年7月29日
	 */
	@PostMapping("/list")
    public MsgModel productList(@RequestBody ParmsModel parm){
		try {
			return messageService.list(parm);
		} catch (Exception e) {
			logger.error("message list ====> {}", e);
			return new MsgModel(ResultCode.FAILURE, "系统错误");
		}
        
    }
	
	/**
	 * @Title: productList
	 * @Description: 修改消息状态
	 * @author zhangxin
	 * @phone 17561783855
	 * @date 2019年7月29日
	 */
	@PostMapping("/updateState")
    public void updateState(@RequestBody Integer id){
		try {
			messageService.updateState(id);
		} catch (Exception e) {
			logger.error("message updateState ====> {}", e);
		}
        
    }
	
	@PostMapping("/findByid")
    public MessageModel findByid(@RequestBody Integer id){
		try {
			return messageService.findByid(id);
		} catch (Exception e) {
			logger.error("message findByid ====> {}", e);
			return new MessageModel();
		}
        
    }
	
	@PostMapping("/selectCount")
    public Map<String, Integer> selectCount(@RequestBody Integer id){
		Map<String, Integer> map = new HashMap<>();
		try {
			return messageService.selectCount(id);
		} catch (Exception e) {
			logger.error("message selectCount ====> {}", e);
			return map;
		}
        
    }
	
	@PostMapping("/changeStates")
	public MsgModel changeStates(@RequestBody String ids) {
		 List<Integer> listObjectFir = (List<Integer>) JSONArray.parse(ids);
		for(Integer id : listObjectFir) {
			messageService.updateState(id);
		}
		return new MsgModel(ResultCode.SUCCESS, "修改成功");
	};
	
	@PostMapping("/del")
	public MsgModel del(@RequestBody String ids) {
		List<Integer> listObjectFir = (List<Integer>) JSONArray.parse(ids);
		for(Integer id : listObjectFir) {
			messageService.del(id);
		}
		return new MsgModel(ResultCode.SUCCESS, "删除数据成功");
	};
	
	
	
	
	
	

}
